#include "..\std.h"
#include "MainWindow.h"

TCHAR szAppName[] = APP_TITLE;

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);

    MainWindow *mainWindow = new MainWindow();

    HDC screen = GetDC(0);
    float dpiScaleX_ = GetDeviceCaps(screen, LOGPIXELSX) / 96.0f;
    float dpiScaleY_ = GetDeviceCaps(screen, LOGPIXELSY) / 96.0f;
    ReleaseDC(0, screen);

    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
        COINIT_DISABLE_OLE1DDE);

    if (SUCCEEDED(hr))
    {
        HINSTANCE hInst = GetModuleHandle(0);

        CreateParams createParams = mainWindow->GetCreatParams(
            szAppName, 
            static_cast<int>(800.0f / dpiScaleX_),
            static_cast<int>(600.0f / dpiScaleY_),
            0,
            WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CLIPCHILDREN,
			WS_EX_CLIENTEDGE
            );

        WNDCLASSEX wcx = mainWindow->GetWindowClass(
            MAKEINTRESOURCE(IDR_MENU1),
            LoadCursor (NULL, IDC_ARROW),
            (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 48, 48, LR_CREATEDIBSECTION),
            (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, LR_CREATEDIBSECTION),
			(HBRUSH)(COLOR_APPWORKSPACE + 1)
            );

        if(SUCCEEDED(mainWindow->Create(wcx, createParams)))
        {
            ShowWindow(mainWindow->GetHWND(), SW_SHOWNORMAL);
            UpdateWindow(mainWindow->GetHWND());
            mainWindow->RunMessageLoop();
        }
    }

    CoUninitialize();

    return 0;
}


